home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
tvcopy.exe
/
PICKCOPY.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-04-18
|
24KB
|
749 lines
{$X+}
program PickCopy;
{This program provides an example of how to pop out of a dialog box, open
a list box containing data from a file, then copy the desired data into
several input lines in the input dialog box. The code to do this was
written by Steve Schafer in response to a question by me.
I have added code that reads, displays, adds to, edits, removes or prints
data in collections, stored in ASCII files. This is modified from a demo
program called Phone.pas available either on CIS or from Borland's BBS.
I was unhappy with having the data stored in an object file since it would
thus be unusable without this program and thus not be amenable to revision
with a simple text editor. Having the data stored in an ASCII file rather
with a stream file violates the principles of encapsulating data and code,
but I love it!.
Be aware that this example shows how Steven Schafer would do the pick and
copy, but he says that there are certainly other ways which would work
just as well.
If you have comments or improvements, please send them along to me:
Stewart Midwinter 74670,1306.
Cheers, SAM }
uses
Memwatch, {warns of unreleased heap, by J.J. Stein}
{available on CIS Pascal Library 1 }
Drivers,Objects,Views,Menus, {Turbo Vision units }
Dialogs,StdDlg,MsgBox,App, {Turbo Vision units }
Gadgets, {Turbo Vision units }
Dos,Crt, {standard Turbo Pascal units }
SList; {handles editing collections }
const
cmNew = 101; { Initialise a new site file }
cmOpen = 102; { Open an existing site file, read into memory }
cmNewDialog = 103; { create Details-type dialog }
cmSiteList = 201; { button to open list box to pick a site }
cmListDlg = 107; { command to open list box dialog }
{ NumSites is the number of sites listed in the "Flight Details" dialog. }
NumSites = 2;
type
PsiteApp = ^TsiteApp;
TsiteApp = object (TApplication)
CurrentFile: PathStr;
HeapViewer: PHeapView;
constructor Init;
procedure NewsiteList;
procedure OpensiteList;
procedure SavesiteList;
procedure HandleEvent (var Event: TEvent); virtual;
procedure InitMenuBar; virtual;
procedure InitStatusLine; virtual;
procedure Idle; virtual;
destructor Done; virtual;
end;
String80 = String[80];
String60 = String[60];
String40 = String[40];
String14 = String[14];
PSiteRec = ^TSiteRec;
TSiteRec = record{object(TObject)}
FNum: Word;
FName: string40;
FLat, FLong: String14;
FInfo: String80;
end;
{ TSite is an object type designed to hold all of the information for a
site. It is a descendant of TObject so that we can store it in a
collection. }
PLSite = ^TLSite;
TLSite = object(TObject)
LName, LLat, LLong,LInfo: PString;
constructor Init( AName: String40;
ALat,ALong: String14;
AInfo: String80);
destructor Done; virtual;
end;
{ TSiteCollection is a simple descendant of TSortedCollection, which
assumes that the objects contained in it are all of type TSite. The only
change is the new Compare method, which sorts the collection on the Name
field of the TSites. }
PLSiteCollection = ^TLSiteCollection; {contains a TLSite object}
TLSiteCollection = object(TSortedCollection)
function Compare (Key1,Key2: pointer): integer; virtual;
procedure FreeItem(Item: pointer); virtual;
end;
{ TSiteListBox is a list box which holds TSites. The GetText method knows
that the items in the list box collection are TSites, so it extracts the
Name field for display in the list box. }
PLSiteListBox = ^TLSiteListBox;
TLSiteListBox = Object(TListBox)
function GetText (item: integer; MaxLen: integer): string; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
end;
PListDialog = ^TListDialog;
TListDialog = object(TDialog)
SitePicklist: PLSiteListBox;
SiteType: PRadioButtons;
constructor Init;
end;
{ TSiteDialog is the "Flight Details" dialog box. Note that I've added
fields corresponding to all of the input lines; this is so that they are
directly accessible from HandleEvent. }
PSiteDialog = ^TSiteDialog;
TSiteDialog = object(TDialog)
SSiteName,SSiteLat,SSiteLong: array[0..NumSites-1] of PInputline;
constructor Init;
procedure HandleEvent(var Event:TEvent); virtual;
end;
SCoordData = record
SiteName: string80;
SiteLat: String14;
SiteLong: String14;
end;
DialogPtr = ^SDialogData;
SDialogData = record {data record for inputting coordinates}
PlaceData: array[0..1] of SCoordData;
end;
NamesArray = array[0..1] of string;
const
SiteDialogData:
SDialogData = (PlaceData: (
(SiteName: ''; SiteLat: '00'; SiteLong: '000'),
(SiteName: ''; SiteLat: '00'; SiteLong: '000')
));
ChosenLocn: NamesArray = ( 'Start point','Finish point');
var
siteApp: TsiteApp; {place here or CurrentFile will not be visible}
var
TheLSiteCollection: PLSiteCollection;
{ TsiteApp methods }
constructor TsiteApp.Init;
var R: TRect;
begin
TApplication.Init;
RegisterObjects;
RegisterViews;
RegisterMenus;
RegisterDialogs;
RegisterApp;
Registersite;
GetExtent(R);
Dec(R.B.X);
R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
HeapViewer := New(PHeapView,Init(R));
Insert(HeapViewer);
CurrentFile := '';
Messagebox( #3'Test of Data Collection &'#13+
#3'Input Dialog w/Pick List',nil,mfinformation+mfOkButton);
end;
procedure TSiteApp.Idle; {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
begin
TApplication.Idle;
HeapViewer^.Update;
end;
{----------------------------- TLSite -----------------------------------}
{ TLSite.Init just takes the string values passed to it and inserts them
into the fields. Note that any blank strings are replaced with a single
space. I've done this because calling NewStr ('') returns a NIL pointer,
which can cause problems in protected mode. }
constructor TLSite.Init (AName: String40; ALat,ALong: String14; AInfo: String80);
begin
TObject.Init;
if AName <> '' then LName := NewStr (AName) else LName := NewStr (' ');
if ALat <> '' then LLat := NewStr (ALat) else LLat := NewStr (' ');
if ALong <> '' then LLong := NewStr (ALong) else LLong := NewStr (' ');
if AInfo <> '' then LInfo := NewStr (AInfo) else LInfo := NewStr (' ');
end;
{ TSite.Done simply releases the memory allocated in TSite.Init. }
destructor TLSite.Done;
begin
DisposeStr (LName);
DisposeStr (LLat);
DisposeStr (LLong);
DisposeStr (LInfo);
TObject.Done;
end;
{------------------------------ end of TLSite ---------------------------}
{---------------------------- TLSiteCollection --------------------------}
{ TSiteCollection.Compare extracts the Name fields from the two items and
compares them alphabetically. }
function TLSiteCollection.Compare (Key1,Key2: Pointer): Integer;
begin
if PLSite (Key1)^.LName^ < PLSite (Key2)^.LName^ then Compare := - 1
else if PLSite (Key1)^.LName^ > PLSite (Key2)^.LName^ then Compare := 1
else Compare := 0;
end;
procedure TLSiteCollection.FreeItem;
begin
if TheLSiteCollection <> nil then
begin
DisposeStr(PLSite(Item)^.LName);
DisposeStr(PLSite(Item)^.LLat);
DisposeStr(PLSite(Item)^.LLong);
DisposeStr(PLSite(Item)^.LInfo);
Dispose(PLSite(Item))
end;
end;
{------------------------- end of TLSiteCollection ---------------------}
{ The FileExists function checks to see if the filename passed to it }
{ refers to an existing file.